Skip to content

feat(contract): contract form, order contract follows its order, Change on activated contracts (#2804) - #2813

Merged
objectstack-fleet[bot] merged 6 commits into
mainfrom
claude/issue-2804-contract-form-change
Nov 26, 2026
Merged

objectstack-fleet[bot] merged 6 commits into
mainfrom
claude/issue-2804-contract-form-change

Conversation

@objectstack-fleet

@objectstack-fleet objectstack-fleet Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Requested by Irene · project thread

Fixes #2804

Clause-②: no
Metadata-protocol: none
Metadata-impact: maintainer — a hook changed (new contract form and Change hook on crm_contract; the end-date-only lock in contract_validation is replaced) and a validation tightened (a direct edit of Contract Value, End Date or Payment Terms on an activated contract, through the form or the API, is now refused)

维护者速读

  • 销售和合同管理员会看到:每份合同多了「合同形式」(订单合同/框架合同/其他);从订单起草的合同金额跟着订单走、不能手改;已生效合同的金额、到期日、付款条件只能通过新的「变更」按钮改,改前改后都留历史。
  • 属于合同管理整改跟踪卡,按 11 月 26 日您「所有需要拍板的都做」的裁决落地。
  • 已生效合同直接改这三项现在会被拒绝并点名字段;老合同在下次保存时自动归类,金额不动。如有问题可整体撤回,老数据只多了一个形式字段。
  • 合并后请安排管理员依次跑两步补数(先算订单金额,再给老合同归类),脚本会列出金额与订单不一致的订单合同供业务核对。

What changes

Contract form. crm_contract.contract_form (select: order / framework / other, required, default framework) sits beside contract_type, which is untouched. It is read-only once the contract leaves Draft, and always read-only on an order contract; no person can write order (only Draft Contract can).

Order contract. sales-order-draft-contract.flow.ts now writes contract_form: 'order' and the new crm_sales_order lookup ("Source Order"; there was no source-order link before). The shared _contract-draft.ts graph is untouched, so the quote-accepted draft stays a framework contract. The value is the order's total_price (the tax-inclusive total). The new summary order_amount (sum of the contract's orders' total_price) drives it: while the contract is Draft, a recompute of order_amount sets contract_value, and contract_value is read-only on the form. The first NULL-to-value computation, from migrate summary-nulls, does not correct a value. The formula order_amount_differs shows Differs from the Order Amount when they part.

Change. Two declarative record-header actions, change_contract (framework/other) and change_order_contract (order), shown only on an activated contract to someone who can edit it. Both require change_reason and change_amendment (a file). The framework action offers New Contract Value; the order action offers only Update from Order. Both offer optional New End Date and New Payment Terms. The new hook contract_form_and_change applies the staged values, recomputes contract_term_months for a new end date, clears the staging fields and leaves status Activated. It creates no change order, does not touch the order and does not re-plan payments. trackHistory is now on contract_value, start_date, end_date, payment_terms, change_reason and change_amendment.

Locks. readonlyWhen makes contract_value, end_date and payment_terms read-only on an activated contract. The hook refuses a person's direct write with RECORD_LOCKED 409, naming the field (reasons: contract_value / end_date / payment_terms / form). The old end-date-shrink RECORD_LOCKED in contract_validation is removed because the new rule covers it. A Change may now move the end date earlier, by design.

Backfill. A contract with no form gets one on its next save: one drafted by Draft Contract and named by an order is an order contract (and gets that order as its Source Order), one with no value is Other, the rest are framework. Values are never changed. scripts/backfill-contract-form.ts (report by default, --apply to write) gives every contract its form at once, then prints the order contracts whose value differs from their order amount. It waits for objectstack migrate summary-nulls --apply --yes and exits non-zero while any order amount is still uncounted.

Text. Labels, help, refusals and action text in en / zh-CN / es-ES / ja-JP. The Contracts manual in three locales, and the in-app help for contracts and orders, in two.

PM assumptions:

  • (a) The platform has no field that is read-only on the form but writable by one action (objectstack#36806). It is enforced with readonlyWhen on the form plus the hook, which writes the staged values. The user outcome matches the ruling.
  • (b) A drafted contract stored no source order. This PR adds one.
  • (c) The order has a tax-inclusive total (total_price). Confirmed.

Tests

Run on head 45291a20. The logs are in the folded blocks below.

  • test/contract-form-change.test.ts (new, 18 tests) covers:

    • the draft order contract's form, source order and value;
    • the draft follows the order;
    • no correction when Order Amount is first computed;
    • person locks on form, value, end date and terms;
    • Change on an order contract (Update from Order) and on a framework contract (new value, end date, terms, term months, status stays Activated, staging cleared);
    • refusals: the action door answers VALIDATION_ERROR 400 for a missing reason or amendment, and the hook answers VALIDATION_FAILED 400 (not_activated, order_value, missing amendment);
    • before/after history in sys_activity;
    • the backfill rule;
    • action visibility and params;
    • trackHistory;
    • the view.
  • test/backfill-contract-form.test.ts (new) covers the script against a stubbed REST server: report, apply, difference list, and the summary-nulls wait.

  • Updated:

    • refusal-envelope (catalogue count 101→108);
    • refusal-labels (new labels);
    • sales-order-draft-contract (the order draft writes the quote keys plus contract_form and crm_sales_order).
  • Also updated, because the change moved them:

    • hooks-runtime-service: the two end-date cases now pin RECORD_LOCKED 409 in both directions;
    • runtime-coverage: lists the new runtime file;
    • README / README.zh-CN / docs/STATUS.md: 56 actions and 636 fields, as pnpm validate prints.

Local runs:

  • pnpm validate, pnpm typecheck, pnpm lint (--strict) and pnpm hygiene: each exit 0. check-docs-locale-parity --base origin/main: exit 0.
  • 74 targeted test files (contract, sales order, o2c, refusal, hooks-runtime, runtime-coverage, every docs-* and i18n-*): 73 passed and 1 failed, 1561 tests passed. The one failure was runtime-coverage; it was fixed and re-run.
  • The five files touched last, on 45291a20: 5/5 files, 166/166 tests.
  • A full vitest run was started locally and stopped after about 30 minutes, unfinished. The part that ran surfaced the three files fixed above. The full suite is CI's run.
Targeted run, 74 files
 Test Files  1 failed | 73 passed (74)
      Tests  1 failed | 1561 passed | 11 skipped (1573)
os-verify-lock: VERDICT command-exit 1 (runtime-coverage: contract_form_and_change not yet named; fixed in 45291a20)
Final head 45291a2, five affected files
 Test Files  5 passed (5)
      Tests  166 passed (166)
os-verify-lock: VERDICT command-exit 0

Acceptance notes

Verification

Measured on a copy of main's database, upgraded with the branch server on port 4012 and driven with headless Chrome.

  1. The branch boots on the old database with no schema errors.
  2. backfill-contract-form.ts: the report, then --apply, gives Formed 6/6 (framework 4, order 2). After migrate summary-nulls, the order amounts are counted.
  3. Draft order contract page: Contract Form "Order Contract", Source Order, Order Amount. Edit form: Contract Form and Contract Value are read-only.
  4. Activated framework contract edit form: Contract Value, End Date, Payment Terms and Contract Form are read-only. A REST PATCH {payment_terms} is refused with 409 RECORD_LOCKED: "An activated contract's Payment Terms change only through Change, with a reason and the signed amendment."
  5. Change without a file: the dialog blocks with "Amendment is required". Change with reason, amendment and new value 250000: 200; the value goes 220000→250000, status stays Activated and the staging fields are cleared. History records contract_value 220000→250000, the reason and the amendment, with actor Dev Admin.
  6. Activated order contract: the dialog shows Update from Order and no value field. Raising the order to 4520 made Differs show; Change with Update from Order set the value 3320→4520 and cleared Differs.

Two-minute check: pnpm exec vitest run test/contract-form-change.test.ts, expected 18 passed. Or, in the app, open an activated contract and click Change: Reason and Signed Amendment are required, and Contract Value is not editable on the form.

Read first, by risk:

  1. src/sales/objects/contract.hook.ts: the contract_form_and_change update branch, especially the draft-follow guard (isSystem, not backfilled, previous order_amount a number) and the Change apply block.
  2. src/sales/objects/contract.object.ts: the readonlyWhen expressions and order_amount_differs.
  3. scripts/backfill-contract-form.ts: the --apply loop and the summary-nulls exit.

🤖 Generated with Claude Code

https://claude.ai/code/session_01J8VVAk8tegvAi1ECkgCFfc

Seat note: head is now 0470529 (origin/main with #2805 merged in). Current test figures: 75 targeted files, 1609 passed / 11 skipped locally; full suite green in CI (Test shards 1–8, Build and Test). See the ACCEPT comment.

…ge on activated contracts (#2804)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J8VVAk8tegvAi1ECkgCFfc
…s and Change (#2804)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J8VVAk8tegvAi1ECkgCFfc
…kfill waits for summary-nulls (#2804)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J8VVAk8tegvAi1ECkgCFfc
… actions (#2804)

The end-date shrink rule is replaced by the Change lock, so the two
hooks-runtime-service cases now pin RECORD_LOCKED 409 in both directions.
The new hook is registered with runtime-coverage, and README / STATUS
state 56 actions and 636 fields as `pnpm validate` prints.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J8VVAk8tegvAi1ECkgCFfc
@vercel

vercel Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
hotcrm Ignored Ignored Nov 26, 2026 10:51am UTC

Request Review

@github-actions github-actions Bot added documentation Improvements or additions to documentation ci/cd CI plumbing and the verification pipeline metadata Declarative metadata — schema, security posture, UI surfaces backend Server-side behaviour — hooks, flows, actions labels Nov 26, 2026
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:hotcrm#1 · huangyiirene · session_01J8VVAk8tegvAi1ECkgCFfc

ACCEPT · 2026-11-26T11:01Z

Head-sha: 0470529b

维护者速读

  • 改了什么:合同加「合同形式」(订单合同 / 框架合同 / 其他);从订单起草的合同金额等于订单含税总额,草稿期跟着订单变,表单上改不了;已生效合同的金额、结束日期、付款条件只能通过「变更」改,必填原因和签署件,留改前改后记录。
  • 老合同下次保存时自动补上合同形式,另有一个回填脚本一次补齐,并列出金额和订单不一致的清单,不强改。
  • 要你做什么:无。按您「做完的,没有问题的都自动合并」,席位直接合并。

席位核对

  • Form: ready PR to main, Fixes #2804; attribution lines and a head note added to the body by the seat.
  • Ruling items 1–7 (Contracts: a contract form (order / framework / other), the order contract's amount follows its order, and an active contract changes only through Change #2804) checked against the diff: contract_form distinct from contract_type, Order option only on order contracts, readonlyWhen + contract_form_and_change hook enforce read-only and refuse direct writes on activated contracts (RECORD_LOCKED 409, field named); order_amount summary over total_price (tax-inclusive) drives the draft follow; order_amount_differs is a sign, never a block; two Change actions (framework new value / order "update from order" only) require reason + signed amendment, keep Activated, history on value, dates, payment terms; no change-order object; backfill on next save + scripts/backfill-contract-form.ts with a difference list, no forced correction.
  • Premises: (a) no platform field is form-readonly but action-writable (objectstack#36806) → hook route, user outcome matches the ruling; (b) source order was not stored → crm_sales_order lookup added; (c) total_price holds.
  • Upgrade safety: contract_form is required without NOT NULL (AGENTS.md metadata rule 11), so installed tables with existing rows upgrade.
  • Gates: every check-run on 0470529 success (Validate/lint/typecheck/build, Typecheck and Build, Build and Test, Quality Checks, Test shards 1–8, Playwright, CodeQL, link-check, Check Changeset, Docs Locale Parity, Label, Vercel). Dev browser pass recorded in the report (Change blocked without amendment; 220000→250000 with history; Update from Order 3320→4520; REST PATCH on activated → 409).
  • Accepted deviations: contract view, backfill script, README/STATUS counts and two re-pinned tests outside the named surface (each follows from the ruling); local full run stopped (lock), full suite is CI's.
  • Out of scope: History shows the amendment as a file id (platform rendering) — noted.
  • Landing: seat lands on the maintainer's standing word 「做完的,没有问题的都自动合并」 (2026-11-26T10:39Z) and her 「2804完成了,你也帮我合并」 (2026-11-26T10:32Z).

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 26, 2026 11:02
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 26, 2026
Merged via the queue into main with commit 3985c89 Nov 26, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Server-side behaviour — hooks, flows, actions ci/cd CI plumbing and the verification pipeline documentation Improvements or additions to documentation metadata Declarative metadata — schema, security posture, UI surfaces

Projects

None yet

2 participants